﻿/*
 * RM2 Character Generator
 * Copyright (C) 2009 James Culshaw
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of 
 * the GNU General Public License as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; 
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RMCharGen.Character
{
    internal enum StatisticType
    {
        CO,
        AG,
        SD,
        Me,
        Re,
        St,
        Qu,
        Pr,
        In,
        EM
    }

    internal class Statistic
    {
        private StatisticType _statType;

        private string _name = String.Empty;
        private string _code = String.Empty;

        private int _initial;
        private int _potential;
        private int _actual;
        private int _developmentPoints;
        private int _normalBonus;
        private int _raceBonus;
        private int _miscellaneousBonus;
        
        public int Initial
        {
            get
            {
                return this._initial;
            }
            set
            {
                this._initial = value;
            }
        }

        public int Potential
        {
            get
            {
                return this._potential;
            }
            set
            {
                this._potential = value;
            }
        }

        public int Actual
        {
            get
            {
                return this._actual;
            }
            set
            {
                this._actual = value;
                DetermineBonus();
                DetermineDevelopmentPoints();
            }
        }

        public int DevelopmentPoints
        {
            get
            {
                return this._developmentPoints;
            }
        }

        public int NormalBonus
        {
            get
            {
                return this._normalBonus;
            }
        }

        public int RaceBonus
        {
            get
            {
                return this._raceBonus;
            }
            set
            {
                this._raceBonus = value;
            }
        }

        public int MiscellaneousBonus
        {
            get
            {
                return this._miscellaneousBonus;
            }
            set
            {
                this._miscellaneousBonus = value;
            }
        }

        public int Total
        {
            get
            {
                return this._normalBonus + this._raceBonus + this._miscellaneousBonus;
            }
        }

        public string Code
        {
            get
            {
                return this._code;
            }
        }

        public string Name
        {
            get
            {
                return this._name;
            }
        }

        public StatisticType Type
        {
            get
            {
                return this._statType;
            }
        }

        private void SetCodeAndName()
        {
            switch (this._statType)
            {
                case StatisticType.AG:
                    this._code = "AG";
                    this._name = "Agility";
                    break;
                case StatisticType.CO:
                    this._code = "CO";
                    this._name = "Constitution";
                    break;
                case StatisticType.EM:
                    this._code = "EM";
                    this._name = "Empathy";
                    break;
                case StatisticType.In:
                    this._code = "In";
                    this._name = "Intuition";
                    break;          
                case StatisticType.Me:
                    this._code = "Me";
                    this._name = "Memory";
                    break;
                case StatisticType.Pr:
                    this._code = "Pr";
                    this._name = "Presence";
                    break;
                case StatisticType.Qu:
                    this._code = "Qu";
                    this._name = "Quickness";
                    break;
                case StatisticType.Re:
                    this._code = "Re";
                    this._name = "Reasoning";
                    break;
                case StatisticType.SD:
                    this._code = "SD";
                    this._name = "Self Discipline";
                    break;
                case StatisticType.St:
                    this._code = "St";
                    this._name = "Strength";
                    break;
            }
        }
        private void DetermineBonus()
        {
            int bonus = 0;

            if (this._actual < 2)
            {
                bonus = -25;
            }
            else if (this._actual == 2)
            { 
                bonus = -20; 
            }
            else if (this._actual > 2 && this._actual < 5)
            {
                bonus = -15;
            }
            else if (this._actual > 4 && this._actual < 10)
            {
                bonus = -10;
            }
            else if (this._actual > 9 && this._actual < 25)
            {
                bonus = -5;
            }
            else if (this._actual > 74 && this._actual < 90)
            {
                bonus = 5;
            }
            else if (this._actual > 89 && this._actual < 95)
            {
                bonus = 10;
            }
            else if (this._actual > 94 && this._actual < 98)
            {
                bonus = 15;
            }
            else if (this._actual > 97 && this._actual < 100)
            {
                bonus = 20;
            }
            else if (this._actual == 100)
            {
                bonus = 25;
            }
            else if (this._actual == 101)
            {
                bonus = 30;
            }
            else if (this._actual > 101)
            {
                bonus = 35;
            }

            this._normalBonus = bonus;

            return;
        }

        private void DetermineDevelopmentPoints()
        {
            int points = 0;

            if (this._statType == StatisticType.CO ||
                this._statType == StatisticType.AG ||
                this._statType == StatisticType.SD ||
                this._statType == StatisticType.Me ||
                this._statType == StatisticType.Re)
            {
                if (this._actual < 5)
                {
                    points = 1;
                }
                else if (this._actual > 4 && this._actual < 15)
                {
                    points = 2;
                }
                else if (this._actual > 14 && this._actual < 25)
                {
                    points = 3;
                }
                else if (this._actual > 24 && this._actual < 40)
                {
                    points = 4;
                }
                else if (this._actual > 39 && this._actual < 60)
                {
                    points = 5;
                }
                else if (this._actual > 59 && this._actual < 75)
                {
                    points = 6;
                }
                else if (this._actual > 74 && this._actual < 85)
                {
                    points = 7;
                }
                else if (this._actual > 84 && this._actual < 95)
                {
                    points = 8;
                }
                else if (this._actual > 94 && this._actual < 100)
                {
                    points = 9;
                }
                else if (this._actual > 99 && this._actual < 102)
                {
                    points = 10;
                }
                else if (this._actual > 101)
                {
                    points = 11;
                }
            }

            this._developmentPoints = points;

            return;
        }

        public Statistic(StatisticType statType)
        {
            this._statType = statType;
            SetCodeAndName();
            DetermineBonus();
            DetermineDevelopmentPoints();
        }
    }
}
